home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / WSKHOSTM.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  169 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.10  $
  6. //
  7. // Winsock for OWL subsystem.
  8. // Based on work by Paul Pedriana, 70541.3223@compuserve.com
  9. //----------------------------------------------------------------------------
  10. #if !defined(OWL_WSKHOSTM_H)
  11. #define OWL_WSKHOSTM_H
  12.  
  13. #if !defined(OWL_DEFS_H)
  14. # include <owl/defs.h>
  15. #endif
  16. #if !defined(OWL_WINDOW_H)
  17. # include <owl/window.h>
  18. #endif
  19. #if !defined(OWL_WINSOCK_H)
  20. # include <owl/winsock.h>
  21. #endif
  22.  
  23. #if defined(BI_NAMESPACE)
  24. namespace OWL {
  25. #endif
  26.  
  27. // Generic definitions/compiler options (eg. alignment) preceeding the 
  28. // definition of classes
  29. #include <services/preclass.h>
  30.  
  31. //
  32. // Forward ref.   
  33. //
  34. class _OWLCLASS TSocketAddress;
  35.  
  36. #define WINSOCK_NOERROR (int)0
  37. #define WINSOCK_ERROR   (int)SOCKET_ERROR
  38.  
  39. //
  40. // Supposedly in RFC 883.
  41. //
  42. #define N_MAX_HOST_NAME 128
  43. #define MSG_HOST_INFO_NOTIFY ((UINT)(WM_USER+303))
  44.  
  45. class _OWLCLASS THostInfoManager;
  46.  
  47. //
  48. // class THostInfoWindow
  49. // ~~~~~ ~~~~~~~~~~~~~~~
  50. // A private class created by THostInfoManager to catch WinSock messages.
  51. //
  52. class _OWLCLASS THostInfoWindow : public TWindow {
  53.   public:
  54.     THostInfoWindow(THostInfoManager* hostInfoManagerParent);
  55.  
  56.     TResult DoNotification(TParam1 param1, TParam2 param2);
  57.  
  58.   public_data:
  59.     // Object to notify of Winsock events
  60.     //
  61.     THostInfoManager* HostInfoManagerParent;
  62.  
  63.   DECLARE_RESPONSE_TABLE(THostInfoWindow);
  64. };
  65.  
  66. //
  67. // class THostEntry
  68. // ~~~~~ ~~~~~~~~~~
  69. // Encapsulates the attributes of a host (hostent).
  70. //
  71. class _OWLCLASS THostEntry : public hostent {
  72.   public:
  73.     THostEntry();
  74.  
  75.     int   GetAddressCount();
  76.     ulong GetINetAddress();
  77.  
  78.     // An internet addressing -specific function.
  79.     //
  80.     ulong GetNthINetAddress(int nIndex = 0);
  81. };
  82.  
  83. //
  84. // class THostInfoManager
  85. // ~~~~~ ~~~~~~~~~~~~~~~~
  86. // Encapsulates hostent database functions.
  87. //
  88. class _OWLCLASS THostInfoManager {
  89.   public:
  90.     THostInfoManager();
  91.     virtual ~THostInfoManager();
  92.  
  93.     int   GetLastError();
  94.     int   GetHostName(char far* name, int nameLength = N_MAX_HOST_NAME);
  95.     int   GetHostAddress(char far* szHostAddress, const char far* szHostName);
  96.     int   GetHostAddress(TSocketAddress& sAddress, const char far* szHostName);
  97.     int   GetHostInfo(THostEntry*& hEntry, const TSocketAddress& sAddress);
  98.     int   GetHostInfo(THostEntry*& hEntry, const char far* szName);
  99.     int   GetHostInfoAsync(HANDLE& hTheHostRequest, TSocketAddress& sAddress);
  100.     int   GetHostInfoAsync(HANDLE& hTheHostRequest, char far* szName);
  101.     int   GetHostInfoAsync(TWindow& wndNotify, HANDLE& hTheHostRequest,
  102.                            TSocketAddress& sAddress, uint nMessage = MSG_HOST_INFO_NOTIFY,
  103.                            char far* chBuffer = 0);
  104.     int   GetHostInfoAsync(TWindow& wndNotify, HANDLE& hTheHostRequest,
  105.                            char far* szName, uint nMessage=MSG_HOST_INFO_NOTIFY,
  106.                            char far* chBuffer = 0);
  107.     int   CancelHostRequest(HANDLE hTheHostRequest = 0);
  108.     short GetHostRequestCompleted();
  109.     static int HostEntryToAddress(THostEntry* hEntry, char far* szAddress);
  110.     static int HostEntryToAddress(THostEntry* hEntry, TSocketAddress& sAddress);
  111.  
  112.     // Set to point to HostInfoBuffer.
  113.     //
  114.   public_data:
  115.     THostEntry*     HostEntry;
  116.  
  117.   protected:
  118.     bool            HostRequestCompleted;              // Flag if host completed last request
  119.     HANDLE          HostRequest;                       // Handle of host to get info about
  120.     int             LastError;                         // Last error code
  121.     char            HostInfoBuffer[MAXGETHOSTSTRUCT];  // Used for calls to WSAAsync...()
  122.     THostInfoWindow HostWindow;                        // Hidden window to catch notifications
  123.  
  124.     void  SetHostRequestCompleted(int error);
  125.  
  126.   friend class THostInfoWindow;
  127. };
  128.  
  129. // Generic definitions/compiler options (eg. alignment) following the 
  130. // definition of classes
  131. #include <services/posclass.h>
  132.  
  133. #if defined(BI_NAMESPACE)
  134. } // namespace OWL
  135. #endif
  136.  
  137. //----------------------------------------------------------------------------
  138. // Inline implementations
  139. //
  140.  
  141. //
  142. // Return the Internet address of the host.
  143. //
  144. inline ulong
  145. THostEntry::GetINetAddress()
  146. {
  147.   return GetNthINetAddress(0);
  148. }
  149.  
  150. //
  151. // Return the last error code.
  152. //
  153. inline int
  154. THostInfoManager::GetLastError()
  155. {
  156.   return LastError;
  157. }
  158.  
  159. //
  160. // Return true if the host complete the last requested transaction.
  161. //
  162. inline short
  163. THostInfoManager::GetHostRequestCompleted()
  164. {
  165.   return HostRequestCompleted;
  166. }
  167.  
  168. #endif  // OWL_WSKHOSTM_H
  169.